package com.justech.eat.service.impl;

import com.justech.eat.entity.Order;
import com.justech.eat.mapper.mysql.OrderMapper;
import com.justech.eat.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.Date;

@Primary
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    OrderMapper orderMapper;

    @Override
    public void add(Order order) {
        Date date = new Date();
        order.setCreateTime(date);
        orderMapper.add(order);


    }

    @Override
    public void delete(long id) {
        orderMapper.deleteById(id);

    }

    @Override
    public void update(long id, String deviceInfo) {
        Order order = orderMapper.queryById(id);
        order.setDeviceInfo(deviceInfo);
        Date date = new Date();
        order.setUpdateTime(date);
        orderMapper.update(order);
    }

    @Override
    public Order queryById(long id) {
        Order order = orderMapper.queryById(id);
        return order;
    }

}
